//package com.surfilter.es;
//
//import com.google.common.collect.Maps;
//import org.elasticsearch.client.Client;
//import org.elasticsearch.common.xcontent.XContentBuilder;
//import org.elasticsearch.common.xcontent.XContentFactory;
//
//import java.io.IOException;
//import java.lang.reflect.Field;
//import java.net.UnknownHostException;
//import java.util.HashMap;
//import java.util.Map;
///**
// * EsLearn
// * Dis:
// * Created by grom on 2017/6/9.
// */
//public class EsLearn {
//    private static Client client;
//
//    static {
//        try {
//            client = new ElasticSearchProvider().getSearchClient("my-application", "47.94.88.80", true, 9300);
//        } catch (UnknownHostException e) {
//            e.printStackTrace();
//        }
//    }
//
//    /**
//     * 创建索引名称
//     * @param indices 索引名称
//     */
//    public static void createCluterName(String indices){
//        client.admin().indices().prepareCreate(indices).execute().actionGet();
////        client.close();
//    }
//
//    /**
//     * 创建mapping
//     * (
//     * feid("indexAnalyzer","ik")该字段分词IK索引 ；
//     * feid("searchAnalyzer","ik")该字段分词ik查询；
//     * 具体分词插件请看IK分词插件说明
//     * )
//     */
//    public static XContentBuilder getBusinessMapping(){
//        new XContentFactory();
//        XContentBuilder mapping = null;
//        try {
//            mapping = XContentFactory.jsonBuilder()
//                .startObject()
//                    .startObject("_all")
//                    .field("store",true)
//                    .endObject()
//                        .startObject("properties")
//                            .startObject("id").field("type","integer").endObject()
//                            .startObject("ename").field("type", "text").field("analyzer","ik_max_word").field("search_analyzer","ik_max_word").endObject()
//                            .startObject("emd5").field("type","keyword").endObject()
//                            .startObject("uucc").field("type","keyword").field("index","not_analyzed").endObject()
//                            .startObject("regNumber").field("type","keyword").field("index","not_analyzed").endObject()
//                            .startObject("businessStatus").field("type","keyword").field("index","not_analyzed").endObject()
//                            .startObject("etype").field("type","keyword").field("index","not_analyzed").endObject()
//                            .startObject("establishTime").field("type","date").endObject()
//                            .startObject("legalRep").field("type","keyword").field("index","not_analyzed").endObject()
//                            .startObject("businessTerm").field("type","date").endObject()
//                            .startObject("regCaptial").field("type","keyword").field("index","not_analyzed").endObject()
//                            .startObject("approveDate").field("type","date").endObject()
//                            .startObject("issueTime").field("type","date").endObject()
//                            .startObject("regAuthority").field("type","keyword").field("index","not_analyzed").endObject()
//                            .startObject("address").field("type","text").field("analyzer","ik_max_word").field("search_analyzer","ik_max_word").endObject()
//                            .startObject("businessScope").field("type","text").field("analyzer","ik_max_word").field("search_analyzer","ik_max_word").endObject()
//                            .startObject("industryType").field("type","integer").field("index","not_analyzed").endObject()
//                            .startObject("constitute").field("type","keyword").endObject()
//                            .startObject("createTime").field("type","date").endObject()
//                            .startObject("updateTime").field("type","date").endObject()
//                            .startObject("level").field("type","integer").field("index","not_analyzed").endObject()
//                            .startObject("provence").field("type","keyword").endObject()
//                            .startObject("city").field("type","keyword").endObject()
//                            .startObject("county").field("type","keyword").field("index","not_analyzed").endObject()
//                        .endObject()
//                .endObject();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return mapping;
//    }
//
//    public static XContentBuilder getPunishMapping(){
//        new XContentFactory();
//        XContentBuilder mapping = null;
//        try {
//            mapping = XContentFactory.jsonBuilder()
//                    .startObject()
//                    .startObject("_all")
//                    .field("store",true)
//                    .endObject()
//                        .startObject("properties")
//                            .startObject("id").field("type","integer").endObject()
//                            .startObject("uuid").field("type", "keyword").field("index","not_analyzed").endObject()
//                            .startObject("emd5").field("type","keyword").endObject()
//                            .startObject("administrativePunishId").field("type","keyword").endObject()
//                            .startObject("punishName").field("type","text").field("analyzer","ik_max_word").field("search_analyzer","ik_max_word").endObject()
//                            .startObject("punishCategoryOne").field("type","keyword").field("index","not_analyzed").endObject()
//                            .startObject("punishCategoryTwo").field("type","keyword").field("index","not_analyzed").endObject()
//                            .startObject("punishCause").field("type","text").field("index","not_analyzed").endObject()
//                            .startObject("punishBasis").field("type","text").field("index","not_analyzed").endObject()
//                            .startObject("punishResult").field("type","text").field("index","not_analyzed").endObject()
//                            .startObject("administrativePeople").field("type","text").field("analyzer","ik_max_word").field("search_analyzer","ik_max_word").endObject()
//                            .startObject("uscc").field("type","string").field("index","not_analyzed").endObject()
//                            .startObject("organizationCode").field("type","keyword").field("index","not_analyzed").endObject()
//                            .startObject("businessCode").field("type","keyword").field("index","not_analyzed").endObject()
//                            .startObject("taxNumber").field("type","keyword").endObject()
//                            .startObject("cid").field("type","keyword").field("index","not_analyzed").endObject()
//                            .startObject("legalPerson").field("type","keyword").endObject()
//                            .startObject("decisionDate").field("type","date").endObject()
//                            .startObject("punishAuthority").field("type","text").field("analyzer","ik_max_word").field("search_analyzer","ik_max_word").endObject()
//                            .startObject("status").field("type","keyword").endObject()
//                            .startObject("updateTime").field("type","date").endObject()
//                            .startObject("memo").field("type","text").endObject()
//                            .startObject("level").field("type","integer").field("index","not_analyzed").endObject()
//                            .startObject("provence").field("type","keyword").endObject()
//                            .startObject("city").field("type","keyword").endObject()
//                            .startObject("county").field("type","keyword").field("index","not_analyzed").endObject()
//                            .startObject("punishType").field("type","integer").field("index","not_analyzed").endObject()
//                            .startObject("authorityType").field("type","integer").field("index","not_analyzed").endObject()
//                            .startObject("punishLevel").field("type","integer").field("index","not_analyzed").endObject()
//                            .startObject("punishCategory").field("type","integer").field("index","not_analyzed").endObject()
//                            .startObject("punishMoney").field("type","double").field("index","not_analyzed").endObject()//贴文包含的地域--一找
//                        .endObject()
//                    .endObject();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return mapping;
//    }
//
//    public static void save() throws UnknownHostException {
//        ElasticSearchProvider provider = new ElasticSearchProvider();
//
//        Map<String,Object> data = Maps.newHashMap();
//
//        data.put("address","北京市怀柔区喇叭沟门满族乡喇叭沟门村12号");
//        data.put("approveDate",null);
//        data.put("issueTime",null);
//        data.put("level",3);
//        data.put("city","北京市");
//        data.put("regAuthority","怀柔分局");
//        data.put("uscc",null);
//        data.put("county","怀柔区");
//        data.put("businessScope","组织文化艺术交流活动（不含演出）；影视策划；销售文具用品、办公用品、计算机软硬件；打字；电脑图文设计、制作；设计、制作、代理、发布广告；组织体育活动（不含比赛）；企业管理咨询、旅游咨询（以上咨询不含中介服务）。");
//        data.put("constitute",null);
//        data.put("businessStatus",null);
//        data.put("businessTerm",null);
//        data.put("updateTime",null);
//        data.put("regCaptial","50万元人民币");
//        data.put("regNumber","110116010074870");
//        data.put("industryType",18);
//        data.put("createTime",null);
//        data.put("provence","北京市");
//        data.put("etype","有限责任公司(自然人投资或控股)");
//        data.put("id",null);
//        data.put("ename","北京大喇叭文化传播有限公司");
//        data.put("legalRep","高文兰");
//        data.put("emd5","E015738878F110ACB4507F39F889EFFB");
//        try {
//            provider.save("qixin","businessInfo","E015738878F110ACB4507F39F889EFFB",data);
//        } catch (UnknownHostException e) {
//            e.printStackTrace();
//        }
//    }
//
//    public static Map objectToMap(Object obj){
//        Map<String,Object> reMap = new HashMap<String,Object>();
//        if (obj == null)
//            return null;
//        Field[] fields = obj.getClass().getDeclaredFields();
//        try {
//            for(int i=0;i<fields.length;i++){
//                try {
//                    Field f = obj.getClass().getDeclaredField(fields[i].getName());
//                    f.setAccessible(true);
//                    Object o = f.get(obj);
//                    reMap.put(fields[i].getName(), o);
//                } catch (NoSuchFieldException e) {
//                    // TODO Auto-generated catch block
//                    e.printStackTrace();
//                } catch (IllegalArgumentException e) {
//                    // TODO Auto-generated catch block
//                    e.printStackTrace();
//                } catch (IllegalAccessException e) {
//                    // TODO Auto-generated catch block
//                    e.printStackTrace();
//                }
//            }
//            if(reMap.containsKey("filePath")){
//                reMap.remove("filePath");
//            }
//        } catch (SecurityException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
//        return reMap;
//    }
//
//    public static void main(String[] args)throws Exception {
////        createCluterName("qixin");
////        PutMappingRequest mapping = Requests.putMappingRequest("qixin").type("punish").source(getPunishMapping());
////        client.admin().indices().putMapping(mapping).actionGet();
//        save();
//    }
//}
